package logic

import (
	"context"
	"goods/models/mysql"

	"goods/goodsrpc/goodsrpc"
	"goods/goodsrpc/internal/svc"

	"github.com/zeromicro/go-zero/core/logx"
)

type GoodListLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewGoodListLogic(ctx context.Context, svcCtx *svc.ServiceContext) *GoodListLogic {
	return &GoodListLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

func (l *GoodListLogic) GoodList(in *goodsrpc.GoodListRequest) (*goodsrpc.GoodListResponse, error) {
	// todo: add your logic here and delete this line

	var good mysql.Good
	mysql.DB.Debug().Where("id = ?", in.GoodId).Find(&good)

	return &goodsrpc.GoodListResponse{
		GoodName:  good.GoodName,
		Title:     good.Title,
		Image:     good.Image,
		ClassName: string(good.ClassId),
		GoodId:    int64(good.ID),
	}, nil
}
